//
//  LBShuangyuShenqingVC.m
//  V-Learn
//
//  Created by Apple on 2019/2/20.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "LBShuangyuShenqingVC.h"
#import "WKShuangyuModel.h"
#import "LBShuangyuTableViewCell.h"
#import "LBSingChooseTableView.h"

#import "ZSSaveTools.h"
#import "LBShuangyuCollectionViewCell.h"
#import "Masonry.h"
#import "UIView+WHC_AutoLayout.h"
#import "UITableViewCell+WHC_AutoHeightForCell.h"
#import "WKShuangyuModel.h"
#import "WKSubjectOptionVOListModel.h"
#import "LBShenheFirleVC.h"
#import "LBShenqingSuccessVC.h"
#import "TestModel.h"
#import "WKShuangyuSuccessViewController.h"
//#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
//#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
#define FONT(a)  [UIFont fontWithName:@"Heiti SC" size:a]


#define Ktimer 10
@interface LBShuangyuShenqingVC ()<UIScrollViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>{
    
    UILabel *timeLabel;
    
    NSArray *_titleArr;
    //正确的
    UILabel *correntLabel;
    /**
     *  错误的个数
     */
    UILabel *errorLabel;
    
    /**
     *  题目
     */
    UILabel *titleLabel;
    
    LBShuangyuTableViewCell *cell;
    /**
     *  目录
     */
    UIButton *catalogBtn;
    /**
     *  答题卡view
     */
    UIView *anmitionView;
    
}
@property (nonatomic, strong) UILabel *countLab;
@property (nonatomic, strong) UILabel *countLab2;
@property(nonatomic,assign) NSInteger currentIndex;
@property(nonatomic,assign) NSInteger Current;

@property(nonatomic,assign) NSInteger currentPage;
@property(nonatomic,strong)NSTimer *countTimer;

@property(nonatomic,strong)UIView *headView;

@property(nonatomic,strong)UIScrollView *scrollView;

@property(nonatomic,strong)UICollectionView *collectionView;

@property (nonatomic, strong) NSMutableArray *dataArray;

@property(nonatomic,strong)    LBSingChooseTableView *MyTable;
@property (nonatomic, strong) NSMutableArray *commitArry;

/**
 *  存放答案的字典
 */
@property(nonatomic,strong)NSMutableDictionary *answerDict;
@property(nonatomic,strong)NSMutableDictionary *answerDict2;
/**
 *  scrollView偏移量
 */

@property(nonatomic,assign)  NSInteger indexPage;
/**
 *  多选答案的数组
 */
@property(nonatomic,strong)NSMutableArray *mulChooseArr;
/**
 *  答案数组
 */
@property(nonatomic,strong)NSMutableArray *dataArr;
/**
 *  存放题目选项数组
 */
@property(nonatomic,strong)NSMutableArray *bigArr;
/**
 *  存放问题的题目数组
 */
@property(nonatomic,strong)NSMutableArray *titlequestArr;
/**
 *  存放block回调的多选答案数组
 */
@property(nonatomic,strong)NSArray *pathArr;


/**
 *  正确答案数组
 */
@property(nonatomic,strong)NSMutableArray *trueAnsArr;

/**
 *  错误答案数组
 */
@property(nonatomic,strong)NSMutableArray *errorAnsArr;

/**
 *  模考回答正确的数组
 */
@property(nonatomic,strong)NSMutableArray *scoreArr;
/**
 *  交卷数组
 */
@property(nonatomic,strong)NSMutableArray *handArr;

@property(nonatomic,assign)NSInteger removeTag;

@property(nonatomic,strong)UIButton *btn;
@end

@implementation LBShuangyuShenqingVC
- (NSMutableArray *)commitArry
{
    if (!_commitArry) {
        _commitArry = [NSMutableArray array];
    }
    return _commitArry;
}
-(NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

-(NSMutableArray *)scoreArr{
    if (!_scoreArr) {
        _scoreArr = [NSMutableArray array];
    }
    return _scoreArr;
}

-(NSMutableArray *)titlequestArr{
    if (!_titlequestArr) {
        _titlequestArr = [NSMutableArray array];
    }
    return _titlequestArr;
}

-(NSMutableArray *)bigArr{
    if (!_bigArr) {
        _bigArr = [NSMutableArray array];
    }
    return _bigArr;
}

-(NSMutableArray *)dataArr{
    if (!_dataArr) {
        _dataArr = [NSMutableArray array];
    }
    return _dataArr;
}

-(NSMutableArray *)mulChooseArr{
    if (!_mulChooseArr) {
        _mulChooseArr = [NSMutableArray array];
    }
    return _mulChooseArr;
}

-(NSMutableDictionary *)answerDict{
    if (!_answerDict) {
        _answerDict = [NSMutableDictionary dictionary];
    }
    return _answerDict;
}
-(NSMutableDictionary *)answerDict2{
    if (!_answerDict2) {
        _answerDict2 = [NSMutableDictionary dictionary];
    }
    return _answerDict2;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults removeObjectForKey:@"MyChooseAnswer"];
    [defaults removeObjectForKey:@"scrollViewAnswer"];
    [defaults removeObjectForKey:@"answerDict"];
    [defaults removeObjectForKey:@"answerDict2"];
    [defaults removeObjectForKey:@"test"];
    [defaults removeObjectForKey:@"cellTagIndex"];;
    
    [defaults synchronize];
}



- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"双语工程申请";

    self.IsPractice = YES;
    _indexPage = 1;
    
    _handArr = [NSMutableArray array];
    
    self.view.backgroundColor = rgb(242,242,242);
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    //确定水平滑动方向
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 65+LBNAVBAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT-181-65-LBNAVBAR_HEIGHT) collectionViewLayout:flowLayout];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.pagingEnabled = YES;
    self.collectionView.scrollEnabled = YES;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    self.collectionView.showsVerticalScrollIndicator = NO;
    self.collectionView.backgroundColor = [UIColor whiteColor];
    //双语申请
    // tableView 偏移20/64适配
    if(@available(iOS 11.0, *)) {
        self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;//UIScrollView也适用
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }

    self.collectionView.allowsMultipleSelection = YES;
    //注册Cell，必须要有
    [self.collectionView registerClass:[LBShuangyuCollectionViewCell class] forCellWithReuseIdentifier:@"LBShuangyuCollectionViewCell"];
    [self.view addSubview:self.collectionView];
    
    
    _dataArr = [NSMutableArray arrayWithObjects:@"后冠的吴茜莉妙答参议员岁的王汉民",@"吴茜莉妙答参议员针对“南海仲裁",@"后冠的吴茜莉妙答20岁的王汉",@"后冠的“南海仲裁”的提问年仅20岁的王汉民", nil];
    
    UIButton *btn = [[UIButton alloc] init];
    self.btn = btn;
    [btn addTarget:self action:@selector(clickNextBtnJump:) forControlEvents:UIControlEventTouchUpInside];
    [btn setTitle:@"下一题" forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:18*ScaleX];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    //    btn.frame = CGRectMake(0, SCREEN_HEIGHT-44, SCREEN_WIDTH, 44);
    [btn setBackgroundImage:LBImage(@"wk_shadow_btn") forState:(UIControlStateNormal)];
    [self.view addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(15*ScaleX);
        make.right.equalTo(-15*ScaleX);
        make.bottom.equalTo(-60*ScaleX);
        make.height.mas_equalTo(44*ScaleX);
    }];
    [self.view addSubview:btn];
    self.countLab = [UILabel labelWithText:@"" andTextColor:rgb(102,102,102) andName:nil andFontSize:15];
    
    [self.view addSubview:self.countLab];
    
    [self.countLab makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-38*ScaleX);
        make.top.mas_equalTo((LBNAVBAR_HEIGHT+37*ScaleX));
    }];
    
    self.countLab2 = [UILabel labelWithText:@"1" andTextColor:rgb(102,102,102) andName:nil andFontSize:15*ScaleX];
    [self.view addSubview:self.countLab2];
    [self.countLab2 makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.countLab.mas_left);
        make.top.mas_equalTo((LBNAVBAR_HEIGHT+37*ScaleX));
    }];
    self.currentIndex = 1;
    [self requestData];
}
- (void)requestData{
    [WYHXNetWorkManager get:WKQuerySubject_WKURL params:@{@"canNullToken":[UserModel getUserModel].token} completionHandler:^(id responseObj, NSError *error) {
        NSString *code = responseObj[@"code"];
        if ([code integerValue]==200) {
//            NSLog(@"%@",responseObj);
            self.dataArray = [WKShuangyuModel mj_objectArrayWithKeyValuesArray:responseObj[@"data"]];
            for (WKShuangyuModel *tModel in self.dataArray) {
                tModel.selectIndex = -1;
            }
            self.countLab.text = [NSString stringWithFormat:@"/%ld",self.dataArray.count];
        }else if([code integerValue]==401){
            NSString *msg = responseObj[@"msg"];
            [MBProgressHUD showSuccess:msg toView:self.view];
            [UserModel clearUserInfo];
            return ;
        }
        [self.collectionView reloadData];
    }];
}
- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
}
- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    
}
#pragma mark - 描述视频路径或者图片路径换成json
- (NSString *)filePathJsonStringArray:(NSMutableArray *)array{
    NSError *fileError = nil;
    NSData *filepathjsonData = [NSJSONSerialization dataWithJSONObject:array
                                                               options:kNilOptions
                                                                 error:&fileError];
    
    NSString *jsonfilePathString = [[NSString alloc] initWithData:filepathjsonData
                                                         encoding:NSUTF8StringEncoding];
    return jsonfilePathString;
}

#pragma mark - scrollView代理
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    /**
     *  视图滚动时将存储到本地的答案删除
     */
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults removeObjectForKey:@"MyChooseAnswer"];
    
    
    CGPoint point = scrollView.contentOffset;
    
    _indexPage = (int)point.x/SCREEN_WIDTH + 1;
    
    
    [defaults synchronize];
    
    if (_indexPage == self.dataArray.count) {
        [self.btn setTitle:@"提交" forState:UIControlStateNormal];
    }else{
        [self.btn setTitle:@"下一题" forState:UIControlStateNormal];
    }
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    NSInteger currentIndex = scrollView.contentOffset.x/[UIScreen mainScreen].bounds.size.width;
    //    NSLog(@"%ld",currentIndex);
    if (currentIndex == self.dataArray.count) {
        return;
    }
    self.currentIndex = currentIndex+1;
    self.countLab2.text = [NSString stringWithFormat:@"%ld",self.currentIndex];
    if (self.currentIndex==self.dataArray.count) {
        [self.btn setTitle:@"提交" forState:UIControlStateNormal];
    }
}
- (void)clickNextBtnJump:(UIButton *)sender{
    
//    NSLog(@"%ld",self.currentIndex);
    //枚举值 注意横竖屏
    self.countLab2.text = [NSString stringWithFormat:@"%ld",self.currentIndex];
    if (self.currentIndex==self.dataArray.count) {
        [sender setTitle:@"提交" forState:UIControlStateNormal];
        self.currentIndex= self.dataArray.count-1;
    }
    [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.currentIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
    NSLog(@"%ld",self.currentIndex);

    __weak typeof(self)weakSelf = self;
    NSString *currentTitle = sender.currentTitle;
    if ([currentTitle isEqualToString:@"提交"]) {
        if (self.commitArry.count<self.dataArray.count) {
            [MBProgressHUD showSuccess:@"请选择完试题后提交" toView:self.view];
            return;
        }else if (self.commitArry.count==self.dataArray.count){
            NSMutableDictionary *data = [NSMutableDictionary dictionary];
            //        NSString *subjectAnswerInfoForms = [self filePathJsonStringArray:self.commitArry];
            [data setObject:self.commitArry forKey:@"subjectAnswerInfoForms"];
            NSMutableDictionary *temp = [NSMutableDictionary dictionary];
            NSString *json = [self jsonStringWithDict:data];
            [temp setObject:json forKey:@"subjectAnswerInfoForms"];
            
            // 请求头
            NSString *accessPath = WKCommitAnswer_WKURL;
            NSString *token = [UserModel getUserModel].token;
            
            // 请求参数字典
            NSDictionary *params = @{@"token":token, @"subjectAnswerInfoForms":self.commitArry};
            
//            NSLog(@"发送请求url=%@,params=%@",accessPath,params);
            
            AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
            
            NSMutableURLRequest *request = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:accessPath parameters:params error:nil];
            request.timeoutInterval = 10.f;
            [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
            [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
            
            
            NSURLSessionDataTask *task = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
//                NSLog(@"-----responseObject===%@+++++",responseObject);
                NSString *code = responseObject[@"code"];
                if ([code integerValue]==200) {
                    NSString *resultContent = responseObject[@"data"][@"resultContent"];
                    NSString *isSuccess = responseObject[@"data"][@"isSuccess"];
                    if ([isSuccess integerValue]==2) {
                    
                        LBShenheFirleVC *fileVC = [LBShenheFirleVC new];
                        fileVC.resultContent = resultContent;
                        [self.navigationController pushViewController:fileVC animated:YES];
//                        [MBProgressHUD showSuccess:@"您的评分较低，请继续努力！" toView:self.view];
                    }else{

                        NSString *courseId = responseObject[@"data"][@"courseId"];
                        WKShuangyuSuccessViewController *successVC = [[WKShuangyuSuccessViewController alloc] init];
                        successVC.resultContent = resultContent;
                        successVC.courseId = courseId;
                        [self.navigationController pushViewController:successVC animated:YES];
//                        [MBProgressHUD showSuccess:@"申请成功!" toView:self.view];
                    }

                }else{
                    LBShenheFirleVC *fileVC = [LBShenheFirleVC new];
                    [self.navigationController pushViewController:fileVC animated:YES];
                }
                
            }];
            
            [task resume];
        
        }
    }
}
#pragma mark 字典转化字符串
- (NSString*)dictionaryToJson:(NSDictionary *)dic
{
    NSError *parseError = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
    
    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
- (NSString *)jsonStringWithDict:(NSDictionary *)dict {
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
    NSString *jsonString;
    if (!jsonData) {
//        NSLog(@"%@",error);
    }else{
        jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
    return jsonString;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    //HQLAppLog(@"点击%ld",indexPath.row);
    //    self.currentPage = indexPath.item;
    
//    NSLog(@"self.currentPage = %ld indexPath.item = %ld indexPath.section = %ld",self.currentPage,indexPath.item,indexPath.section);
    
}




-(void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated{
    
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return self.dataArray.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *Idenfire = @"LBShuangyuCollectionViewCell";
    UICollectionViewCell *mycell = [collectionView dequeueReusableCellWithReuseIdentifier:Idenfire forIndexPath:indexPath];
    mycell.contentView.backgroundColor = rgb(242,242,242);
    if (mycell) {
        
        for (UIView *view in mycell.contentView.subviews) {if (view) {[view removeFromSuperview];}}}
    
    
    __weak typeof(self)weakSelf = self;
    
    self.pathArr = [NSMutableArray array];
    
    //单选
    _MyTable = [LBSingChooseTableView ShareTableWithFrame:CGRectMake(0, 65, SCREEN_WIDTH, ScreenH-110)];
    
    WKShuangyuModel *model = self.dataArray[indexPath.item];
    _MyTable.model1 = model;
    _MyTable.dataArr =  model.subjectOptionVOList;//self.dataArr;
    
    [_MyTable createHeadView:model.subjectName];//[NSString stringWithFormat:];
    
    
    
    /**
     *  历史已返回答案不能再次选择
     */
    if (self.isHistory) {
        _MyTable.dontSelectCell = NO;
    }
    /**
     *  练习已有选择的答案后，不能选择
     */
    if (self.IsPractice) {
        
        _MyTable.preiceDontSelect = NO;
    }
    
    
    NSInteger cRow = indexPath.row;
    
    _MyTable.block = ^(NSString * _Nonnull chooseContent, NSIndexPath * _Nonnull indexPath, NSString * _Nonnull optionId, NSString * _Nonnull score) {
        
        if (weakSelf.IsPractice ){
            
            [weakSelf ExamAnswerWith:[NSString stringWithFormat:@"%ld",cRow+1] andWith:@"8" AndWith:@"我是答案的解析，屌不屌" andWithTitle:[NSString stringWithFormat:@"%ld",cRow+1]andWith:@"4"];
        }
        
        //存储答案
        [weakSelf.answerDict setValue:chooseContent forKey:[NSString stringWithFormat:@"%ld",cRow+1]];
        
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setValue:weakSelf.answerDict forKey:@"answerDict"];
        
        [defaults synchronize];
        
        NSString *value = [weakSelf.answerDict objectForKey:[NSString stringWithFormat:@"%ld",cRow + 1]];
        
        NSMutableDictionary *data = [NSMutableDictionary dictionary];
        
        [data setObject:value forKey:@"optionName"];
        [data setObject:model.subjectId forKey:@"subjectId"];
        [data setObject:model.subjectName forKey:@"subjectName"];
        [data setObject:optionId forKey:@"optionId"];
        [data setObject:score forKey:@"score"];
        
        if (cRow >= weakSelf.commitArry.count) {
            [weakSelf.commitArry addObject:data];
        }else {
            [weakSelf.commitArry replaceObjectAtIndex:cRow withObject:data];
        }
        
    };
    // 滑动返回进入上一个记录
    if ([self.answerDict objectForKey:[NSString stringWithFormat:@"%ld",indexPath.row + 1]]) {
        
        
        NSString *str = [self.answerDict objectForKey:[NSString stringWithFormat:@"%ld",indexPath.row + 1]];
        //*显示用户之前选择的答案*/
        //str代表用户已经选的答案 8是正确答案此处写死
        [weakSelf ExamAnswerWith:str andWith:@"8" AndWith:@"我是答案的解析，屌不屌"andWithTitle:[NSString stringWithFormat:@"%ld",indexPath.row+1]andWith:@"12"];
        
    }
    
    
    [mycell.contentView addSubview:self.MyTable];
    
    
    return mycell;
}

#pragma mark - 用户单选的时候
/**
 *  单选
 *
 *  @param flast      错误答案
 *  @param tureAnswer 正确答案
 *  @param JieXi      解析
 */
-(void)ExamAnswerWith:(NSString *)flast andWith:(NSString *)tureAnswer AndWith:(NSString *)JieXi andWithTitle:(NSString *)title andWith:(NSString *)seqStr{
    
    
    NSString *myStr = nil;
    
    UILabel *labelll = [[UILabel alloc]init];
    //        labelll.text = flast;
    labelll.textColor = [UIColor blueColor];
    /**
     *  正确答案
     */
    UILabel *correctLabel = [[UILabel alloc]init];
    correctLabel.textColor = [UIColor redColor];
    //correctLabel.text = tureAnswer;
    
    UILabel *resloveLabel = [[UILabel alloc]init];
    resloveLabel.text = JieXi;//@"你选择错了，再交点学费继续学习一下吧，你选择错了，再交点学费继续学习一下吧";
    resloveLabel.textColor = [UIColor darkGrayColor];
    
    if ([flast integerValue] == 1) {
        labelll.text = @"A";
        myStr = @"1";
        
    }else if ([flast integerValue] == 2 ){
        labelll.text = @"B";
        myStr = @"2";
        
    }else if ([flast integerValue] == 3 ){
        labelll.text = @"C";
        myStr = @"4";
        
    }else if ([flast integerValue] == 4 ){
        labelll.text = @"D";
        myStr = @"8";
        
    }
    
    if (self.isHistory) {
        
        if ([flast integerValue] == 1) {
            labelll.text = @"A";
            myStr = @"1";
            
        }else if ([flast integerValue] == 2 ){
            labelll.text = @"B";
            myStr = @"2";
            
        }else if ([flast integerValue] == 4 ){
            labelll.text = @"C";
            myStr = @"4";
            
        }else if ([flast integerValue] == 8 ){
            labelll.text = @"D";
            myStr = @"8";
            
        }
        
    }
    
    
    if ([tureAnswer integerValue] == 1) {
        correctLabel.text = @"A";
    }else if([tureAnswer integerValue] == 2){
        correctLabel.text = @"B";
    }else if([tureAnswer integerValue] == 4){
        correctLabel.text = @"C";
    }else if([tureAnswer integerValue] == 8){
        correctLabel.text = @"D";
    }
    
    
    //    HQLAppLog(@"%@---%@---%@",labelll.text,correctLabel.text,title);
//    NSLog(@"%@%@%@",labelll.text,correctLabel.text,title);
    
    /**
     *  重新选择答案时，移除以前的
     */
    if (self.handArr.count !=0) {
        for (int i = 0; i < self.handArr.count; i++) {
            NSArray *aa = [self.handArr[i] allKeys];
            if ([aa containsObject:seqStr]) {
                [self.handArr removeObjectAtIndex:i];
            }
        }
        
        
        for (int i = 0; i< self.handArr.count; i++) {
            NSDictionary *dict1 = self.handArr[i];
            if (dict1[@"eid"] == seqStr) {
                [self.handArr removeObjectAtIndex:i];
                
            }
            
        }
        
    }
    
    
    
    
    /**
     *  回答正确
     */
    if ([labelll.text isEqualToString:correctLabel.text]) {
        
        NSMutableArray *pathMuArr  =[ NSMutableArray array];
        
        if (self.IsTadayExam) {
            
            
            NSMutableDictionary *dict = [NSMutableDictionary dictionary];
            [dict setObject:myStr forKey:@"answer"];
            [dict setObject:seqStr forKey:@"eid"];
            
            [dict setObject:@"1" forKey:@"isright"];
            [self.handArr addObject:dict];
            
            
            [pathMuArr addObject:title];
            
            NSMutableArray *listAry = [[NSMutableArray alloc]init];
            for (NSString *str in self.scoreArr) {
                if (![listAry containsObject:str]) {
                    [listAry addObject:str];
                }
            }
            
            [self.scoreArr addObject:pathMuArr];
            
        }else{
            
            [_MyTable createFootViewWithAnswer:correctLabel andWithOtherAnswer:labelll AndWith:YES andWithCorrent:YES andResolve:resloveLabel];
            
        }
        [self.trueAnsArr addObject:title];
        
        
        
        /**
         只记录题号，如果题号相同就移除
         */
        NSMutableArray *listAry = [[NSMutableArray alloc]init];
        for (NSString *str in self.trueAnsArr) {
            if (![listAry containsObject:str]) {
                [listAry addObject:str];
            }
        }
        
        
        correntLabel.text = [NSString stringWithFormat:@"%ld",listAry.count];
        
        
        
    }else{
        
        if (self.IsTadayExam){
            
            NSMutableDictionary *dict = [NSMutableDictionary dictionary];
            [dict setObject:seqStr forKey:@"eid"];
            [dict setObject:myStr forKey:@"answer"];
            [dict setObject:@"0" forKey:@"isright"];
            [self.handArr addObject:dict];
            
            
        }else{
            
            /**
             *  用户没有选择答案的时候
             */
            //  HQLAppLog(@"---%@",labelll.text);
            if (labelll.text == nil) {
                UILabel *nullLabel = [[UILabel alloc]init];
                nullLabel.text = @"空";
                [_MyTable createFootViewWithAnswer:correctLabel andWithOtherAnswer:nullLabel AndWith:YES andWithCorrent:NO andResolve:resloveLabel];
                
                
            }else{
                
                [_MyTable createFootViewWithAnswer:correctLabel andWithOtherAnswer:labelll AndWith:YES andWithCorrent:NO andResolve:resloveLabel];
                
            }
            
            
            
        }
        
        
        [self.errorAnsArr addObject:title];
        /**
         只记录题号，如果题号相同就移除
         */
        NSMutableArray *listAry = [[NSMutableArray alloc]init];
        for (NSString *str in self.errorAnsArr) {
            if (![listAry containsObject:str]) {
                [listAry addObject:str];
            }
        }
        errorLabel.text = [NSString stringWithFormat:@"%ld",listAry.count];
        
    }
    
    
}


#pragma mark --UICollectionViewDelegate
- (UIEdgeInsets)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(0, 0, 0, 0); // 上, 左, 下, y右
}


#pragma mark --设置每个cell的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    return CGSizeMake(SCREEN_WIDTH , SCREEN_HEIGHT-50);
}

//定义每个UICollectionView 的 margin
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}
// 两行之间的最小间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}

#pragma mark - 字典转json
-(NSString *)changeJsonStrWith:(NSMutableArray *)hanArr{
    
    //将字典转为json格式的数据
    // NSJSONWritingPrettyPrinted 转化的json数据有换位符 /n
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:hanArr options:0 error:nil];
    NSMutableData *data = [NSMutableData dataWithData:jsonData];
    NSString *JsonStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
    
    return JsonStr;
    
}

-(NSMutableArray *)trueAnsArr{
    if (!_trueAnsArr) {
        _trueAnsArr = [NSMutableArray array];
    }
    return _trueAnsArr;
}
-(NSMutableArray *)errorAnsArr{
    if (!_errorAnsArr) {
        _errorAnsArr = [NSMutableArray array];
    }
    return _errorAnsArr;
}


@end
